//
// Created by Jisam on 2024/7/28 20:06.
// solve e
#include <bits/stdc++.h>

#define PSI pair<string,int>
#define PII pair<int,int>
#define PDI pair<double,int>
#define PDD pair<double,double>
#define VVI vector<vector<int>>
#define VI vector<int>
#define VS vector<string>

#define PQLI priority_queue<int, vector<int>, less<int>>
#define PQGI priority_queue<int, vector<int>, greater<int>>
using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;

using namespace std;


void solve() {
    int n;
    cin >> n;
    PQLI pq;
    unordered_map<int, int> mp;
    int x;
    vector<int> cnt(1e6+5);
    for (int i = 0; i < n; i++) {
        cin >> x;
        mp[x]++;
    }
    int ans = 0;
    while (mp.find(ans) != mp.end() && mp.find(ans)->second != 0) {

        if(mp.find(ans * 2) != mp.end()){
            mp[ans * 2 ] --;
            mp[ans ] ++;
            ans++;
        }
        if(mp.find(ans * 2 -1) != mp.end()){
            mp[ans * 2 -1] --;
            mp[ans ] ++;
            ans++;
        }
        ans++;
        cout << ans  << "\n";
    }

    for(auto [x,y] : mp){
        cout << x << "  " << y <<"\n";
        if(x < ans) continue;
        for(int i = 0 ;i < y ; i++)pq.emplace(x);
    }

    while (!pq.empty()) {

        int t = pq.top();
        pq.pop();
        cout << t << " ";
        if(t > ans) {
            pq.emplace(t / 2);
            if(t/2 == ans )  ans ++;
        }

    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
//    cin >> T;
    while (T--) solve();
//    cout << "\n"[];
    return 0;
}